<?php

hc_core_ClassLoader::load('halo_AbstractView');
hc_core_ClassLoader::load('skittle_Skittle');
hc_core_ClassLoader::load('halo_SkittleHelperMappingAdapter');

class halo_SkittleView extends halo_AbstractView {
    protected $additionalConfigurationKeys = array('noShell', 'shell', 'helpers', 'theme');
    public function __construct($viewName = null, $url = null) {
        parent::__construct($viewName, $url);
    }
    public function doRender(array $model, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {

        // Get the theme.
        $theme = $this->getAdditionalConfiguration('theme');

        $skittle = new skittle_Skittle(HALO_VIEWS_DIR, HALO_THEMES_DIR, $theme);

        $viewHelperMappings = $this->getViewHelperMappings($httpRequest, $httpResponse);

        if ( $viewHelperMappings ) {
            $skittleHelpers = array();
            foreach ( $viewHelperMappings as $viewHelperMapping ) {
                $skittleHelpers[] = new halo_SkittleHelperMappingAdapter($viewHelperMapping);
            }
            $skittle->addHelperMappings($skittleHelpers);
        }

        foreach ( $this->getConfiguredHelpersMap() as $variableName => $helperName ) {
            $skittle->addHelper($variableName, $helperName);
        }

        $shell = $this->getAdditionalConfiguration('shell');
        $noShell = $this->getAdditionalConfiguration('noShell');

        if ( ( null !== $shell ) and ! $noShell ) {
            $rendered = $skittle->stringShellInc($shell, $this->url, $model);
        } else {
            $rendered = $skittle->stringInc($this->url, $model);
        }

        return $rendered;

    }

}

?>
